/*
 * Copyright (c) 2023 Cshoo Org. All Rights Reserved.
 */

package org.cshoo.tattoo.datacenter.domain.repository;

import org.cshoo.tattoo.datacenter.domain.po.Lookup;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author 杨翼
 * @since 1.0
 */
public interface ILookupRepository extends CrudRepository<Lookup, Long> {

    /**
     * 根据编号查询lookup
     *
     * @param code 编号
     * @return lookup
     */
    Lookup findByCode(String code);

    /**
     * 分页查询lookup
     *
     * @param keyword 查询关键字
     * @param pageable             分页对象
     * @return lookup分页列表
     */
    @Query("SELECT lookup FROM Lookup lookup WHERE lookup.code like %:#{#keyword}% OR lookup.name LIKE %:#{#keyword}%")
    Page<Lookup> findLookup(String keyword, Pageable pageable);

    /**
     * 更新lookup基本信息
     *
     * @param lookup lookup
     */
    @Query("update Lookup lookup set lookup.name = :#{#lookup.name}, lookup.description = :#{#lookup.description}, lookup.lastModifiedBy = :#{#lookup.lastModifiedBy}, lookup.lastModifiedDate = :#{#lookup.lastModifiedDate} where lookup.id = :#{#lookup.id}")
    @Transactional
    @Modifying
    void updateLookup(Lookup lookup);
}
